$(function(){
	//pageInit();
});
function pageInit(){
	createList();
	addAction();
}
function addAction(){
	$(".item-close").click(function(){
		closeTab();
	});
	$(".right-pane-title>div").live("click",function(){
		selectTab($(this).attr("src"));
	});
}
var showfield = "cntext";
function createList(){
	$("#listMenu").listMenu({
		parentField:"pid",
		idField:"id",
		captionField:"text",
		rootId:"root",
		multSelect: true,
		onCreateText:function(data){
			return data[showfield];
		},
		onClickItem:function(data){
			if(data.url){
				addTab(data[showfield],ctx+data.url);
			}
		}
	});//初始化
	loadMenu();
}
function changeLan(lan){
	if(lan===1){
		showfield="text";
		$("#lan_en").hide();
		$("#lan_cn").show();
	}else if(lan ===2){
		showfield ="cntext";
		$("#lan_cn").hide();
		$("#lan_en").show();
	}
	loadMenu();
}
function loadMenu(){
	var data = [
	            {id:"001",text:"Loading Data",cntext:"加载数据",pid:"root"},
	            {id:"001001",text:"XML Data",cntext:"XML数据",pid:"001",url:"/loading_data/xml_data/index.jsp"},
	            {id:"001002",text:"JSON Data",cntext:"JSON数据",pid:"001",url:"/loading_data/json_data/index.jsp"},
	            {id:"001003",text:"Load once",cntext:"一次性加载",pid:"001",url:"/loading_data/load_once/index.jsp"},
	            {id:"001004",text:"Array Data",cntext:"数组数据",pid:"001",url:"/loading_data/array_data/index.jsp"},
	            {id:"002",text:"Manipulating",cntext:"操作",pid:"root"},
	            {id:"002001",text:"Grid Data",cntext:"表格数据",pid:"002",url:"/manipulating/grid_data/index.jsp#"},
	            {id:"002002",text:"Get Methods",cntext:"GET类方法",pid:"002",url:"/manipulating/get_methods/index.jsp"},
	            {id:"002003",text:"Set Methods",cntext:"SET类方法",pid:"002",url:"/manipulating/set_methods/index.jsp"},
	            {id:"003",text:"Advanced",cntext:"高级",pid:"root"},
	            {id:"003001",text:"Multi Select",cntext:"多选",pid:"003",url:"/advanced/multi_select/index.jsp"},
	            {id:"003002",text:"Master Detail",cntext:"主从",pid:"003",url:"/advanced/master_detail/index.jsp"},
	            {id:"003003",text:"Subgrid",cntext:"多级表格1",pid:"003",url:"/advanced/subgrid/index.jsp"},
	            {id:"003004",text:"Grid as Subgrid",cntext:"多级表格2",pid:"003",url:"/advanced/grid_as_subgrid/index.jsp"},
	            {id:"003005",text:"Resizing",cntext:"列宽",pid:"003",url:"/advanced/resizing/index.jsp"},
	            {id:"003006",text:"Search Big Sets",cntext:"搜索大数据",pid:"003",url:"/advanced/search_big_sets/index.jsp"},
	            {id:"004",text:"New since beta 3.0",cntext:"版本3.0新特征",pid:"root"},
	            {id:"004001",text:"Custom Multi Select",cntext:"自定义多选",pid:"004",url:"/new_since_3/custom_multi_select/index.jsp"},
	            {id:"004002",text:"Subgrid with JSON",cntext:"JSON版多级表格",pid:"004",url:"/new_since_3/subgrid_with_JSON/index.jsp"},
	            {id:"004003",text:"After Load Callback",cntext:"数据加载完成回调",pid:"004",url:"/new_since_3/after_load_callback/index.jsp"},
	            {id:"004004",text:"Resizable Columns",cntext:"调整列宽",pid:"004",url:"/new_since_3/resizable_columns/index.jsp"},
	            {id:"004005",text:"Hide/Show Columns",cntext:"显示/隐藏列",pid:"004",url:"/new_since_3/shide_show_columns/index.jsp"},
	            {id:"005",text:"Row Editing (new)",cntext:"行编辑(新)",pid:"root"},
	            {id:"005001",text:"Basic Example",cntext:"基本实例",pid:"005",url:"/row_editing/basic_example/index.jsp"},
	            {id:"005002",text:"Custom Edit",cntext:"自定义编辑",pid:"005",url:"/row_editing/custom_edit/index.jsp"},
	            {id:"005003",text:"Using Events",cntext:"使用事件",pid:"005",url:"/row_editing/using_events/index.jsp"},
	            {id:"005004",text:"Full Control",cntext:"全列编辑",pid:"005",url:"/row_editing/full_control/index.jsp"},
	            {id:"005005",text:"Input types",cntext:"输入类型",pid:"005",url:"/row_editing/input_types/index.jsp"},
	            {id:"005006",text:"Inline Navigator (new)",cntext:"内嵌导航(新)",pid:"005",url:"/row_editing/inline_navigator/index.jsp"},
	            {id:"006",text:"Data Mapping",cntext:"数据结构",pid:"root"},
	            {id:"006001",text:"XML Mapping",cntext:"XML结构",pid:"006",url:"/data_mapping/xml_mapping/index.jsp"},
	            {id:"006002",text:"JSON Mapping",cntext:"JSON结构",pid:"006",url:"/data_mapping/json_mapping/index.jsp"},
	            {id:"006003",text:"Data Optimization",cntext:"数据优化",pid:"006",url:"/data_mapping/data_optimization/index.jsp"},
	            {id:"007",text:"Integrations",cntext:"集成插件",pid:"root"},
	            {id:"007001",text:"UI Datepicker",cntext:"时间选择器",pid:"007",url:"/integrations/ui_datepicker/index.jsp"},
	            {id:"008",text:"Live Data Manipulation",cntext:"实时数据处理",pid:"root"},
	            {id:"008001",text:"Searching Data",cntext:"搜索数据",pid:"008",url:"/live_data_manipulation/searching_data/index.jsp"},
	            {id:"008002",text:"Edit row",cntext:"编辑行",pid:"008",url:"/live_data_manipulation/edit_row/index.jsp"},
	            {id:"008003",text:"Add row",cntext:"新增行",pid:"008",url:"/live_data_manipulation/add_row/index.jsp"},
	            {id:"008004",text:"Delete row",cntext:"删除航",pid:"008",url:"/live_data_manipulation/delete_row/index.jsp"},
	            {id:"008005",text:"Navigator",cntext:"导航",pid:"008",url:"/live_data_manipulation/navigator/index.jsp"},
	            {id:"009",text:"New in version 3.1",cntext:"版本3.1新特征",pid:"root"},
	            {id:"009001",text:"Toolbars and userdata",cntext:"工具栏和用户数据",pid:"009",url:"/new_3_1/toolbars_and_userdata/index.jsp"},
	            {id:"009002",text:"New Methods",cntext:"新方法",pid:"009",url:"/new_3_1/new_methods/index.jsp"},
	            {id:"009003",text:"Post Data",cntext:"发送数据",pid:"009",url:"/new_3_1/post_data/index.jsp"},
	            {id:"009004",text:"Common Params",cntext:"常见参数",pid:"009",url:"/new_3_1/common_params/index.jsp"},
	            {id:"010",text:"New in version 3.2",cntext:"版本3.2新特征",pid:"root"},
	            {id:"010001",text:"New Methods 3.2",cntext:"新方法",pid:"010",url:"/new_3_2/new_methods_3_2/index.jsp"},
	            {id:"010002",text:"Initial hidden grid",cntext:"最初隐藏表格",pid:"010",url:"/new_3_2/initial_ hidden_grid/index.jsp"},
	            {id:"010003",text:"After Insert Row event",cntext:"插入行后事件",pid:"010",url:"/new_3_2/after_insert_row_event/index.jsp"},
	            {id:"010004",text:"Controlling server errors",cntext:"控制服务器错误",pid:"010",url:"/new_3_2/controling_server_errors/index.jsp"},
	            {id:"010005",text:"Hide/Show columns",cntext:"隐藏/显示行",pid:"010",url:"/new_3_2/hide_show_columns/index.jsp"},
	            {id:"010006",text:"Custom Button and Forms",cntext:"自定义按钮和表单",pid:"010",url:"/new_3_2/custom_button_and_forms/index.jsp"},
	            {id:"010007",text:"Client Validation",cntext:"客户端验证",pid:"010",url:"/new_3_2/client_validation/index.jsp"},
	            {id:"011",text:"New in version 3.3",cntext:"版本3.3新特征",pid:"root"},
	            {id:"011001",text:"Dynamic height and width",cntext:"动态高度和宽度",pid:"011",url:"/new_3_3/dynamic_height_and_width/index.jsp"},
	            {id:"011002",text:"Tree Grid",cntext:"树表格",pid:"011",url:"/new_3_3/tree_grid/index.jsp"},
	            {id:"011003",text:"Cell Editing",cntext:"单元格编辑",pid:"011",url:"/new_3_3/cell_editing/index.jsp"},
	            {id:"011004",text:"Visible Columns",cntext:"可见列",pid:"011",url:"/new_3_3/visible_columns/index.jsp"},
	            {id:"011005",text:"HTML Table to Grid",cntext:"table转jqGrid",pid:"011",url:"/new_3_3/html_table_to_grid/index.jsp"},
	            {id:"011006",text:"Multiple Toolbar Search",cntext:"工具栏多字段搜索",pid:"011",url:"/new_3_3/multiple_toolbar_search/index.jsp"},
	            {id:"011007",text:"Multiple Form Search",cntext:"表单多字段搜索",pid:"011",url:"/new_3_3/multiple_form_search/index.jsp"},
	            {id:"011008",text:"Data type as function",cntext:"function类型数据",pid:"011",url:"/new_3_3/data_type_as_function/index.jsp"},
	            {id:"011009",text:"Row Drag and Drop",cntext:"行的拖拽",pid:"011",url:"/new_3_3/row_drag_and_drop/index.jsp"},
	            {id:"012",text:"New in version 3.4",cntext:"版本3.4新特征",pid:"root"},
	            {id:"012001",text:"Formater",cntext:"格式化",pid:"012",url:"/new_3_4/formater/index.jsp"},
	            {id:"012002",text:"Custom Formater",cntext:"自定义格式化",pid:"012",url:"/new_3_4/custom_formater/index.jsp"},
	            {id:"012003",text:"Import Configuration from XML",cntext:"导入XML配置",pid:"012",url:"/new_3_4/import_configuration_from_xml/index.jsp"},
	            {id:"012004",text:"Autoloading data when scroll",cntext:"滚动自动加载数据",pid:"012",url:"/new_3_4/autoloading_data_when_scroll/index.jsp"},
	            {id:"012005",text:"Scroll with dynamic row select",cntext:"根据航选择自动滚动",pid:"012",url:"/new_3_4/scroll_with_dynamic_row_select/index.jsp"},
	            {id:"012006",text:"Tree Grid Adjacency model",cntext:"树表格的相邻模式",pid:"012",url:"/new_3_4/tree_grid_adjacency_model/index.jsp"},
	            {id:"013",text:"New in version 3.5",cntext:"版本3.5新特征",pid:"root"},
	            {id:"013001",text:"Autowidth and row numbering",cntext:"自动宽度和行编号",pid:"013",url:"/new_3_5/autowidth_and_row_numbering/index.jsp"},
	            {id:"013002",text:"Grid view mode",cntext:"表格视图模式",pid:"013",url:"/new_3_5/grid_view_mode/index.jsp"},
	            {id:"013003",text:"Integrated Search Toolbar",cntext:"集成搜索工具栏",pid:"013",url:"/new_3_5/integrated_search_toolbar/index.jsp"},
	            {id:"013004",text:"Advanced Searching",cntext:"高级搜索",pid:"013",url:"/new_3_5/advanced_searching/index.jsp"},
	            {id:"013005",text:"Form Improvements",cntext:"表单改进",pid:"013",url:"/new_3_5/form_improvements/index.jsp"},
	            {id:"013006",text:"TreeGrid real world example",cntext:"现实中的树表格实例",pid:"013",url:"/new_3_5/treegrid_real_world_example/index.jsp"},
	            {id:"013007",text:"Form Navigation",cntext:"表单导航",pid:"013",url:"/new_3_5/form_navigation/index.jsp"},
	            {id:"013008",text:"Summary Footer Row",cntext:"汇总页脚行",pid:"013",url:"/new_3_5/summary_footer_row/index.jsp"},
	            {id:"013009",text:"View sortable columns",cntext:"排序列的可见性",pid:"013",url:"/new_3_5/view_sortable_columns/index.jsp"},
	            {id:"014",text:"New in version 3.6",cntext:"版本3.6新特征",pid:"root"},
	            {id:"014001",text:"New API",cntext:"新接口",pid:"014",url:"/new_3_6/new_api/index.jsp"},
	            {id:"014002",text:"RTl Support",cntext:"RTL支持",pid:"014",url:"/new_3_6/rtl_example/index.jsp"},
	            {id:"014003",text:"Column Reordering",cntext:"列重新排序",pid:"014",url:"/new_3_6/column_reordering/index.jsp"},
	            {id:"014004",text:"Column Chooser",cntext:"列选择",pid:"014",url:"/new_3_6/column_chooser/index.jsp"},
	            {id:"014005",text:"Custom Validation",cntext:"自定义验证",pid:"014",url:"/new_3_6/custom_validation/index.jsp"},
	            {id:"014006",text:"Create Custom input element",cntext:"创建自定义输入元素控件",pid:"014",url:"/new_3_6/create_custom_input_element/index.jsp"},
	            {id:"014007",text:"Ajax Improvements",cntext:"AJAX改进",pid:"014",url:"/new_3_6/ajax_improvements/index.jsp"},
	            {id:"014008",text:"True scrolling Rows",cntext:"滚动加载行数据",pid:"014",url:"/new_3_6/true_scrolling_rows/index.jsp"},
	            {id:"014009",text:"Sortable Rows",cntext:"排序行",pid:"014",url:"/new_3_6/sortable_rows/index.jsp"},
	            {id:"014010",text:"Drag and Drop Rows",cntext:"拖拽行",pid:"014",url:"/new_3_6/drag_and_drop_rows/index.jsp"},
	            {id:"014011",text:"Resizing Grid",cntext:"改变grid大小",pid:"014",url:"/new_3_6/resizing_grid/index.jsp"},
	            {id:"015",text:"New in version 3.7",cntext:"版本3.7新特征",pid:"root"},
	            {id:"015001",text:"Load array data at once",cntext:"一次性加载数组数据",pid:"015",url:"/new_3_7/load_array_data_at_once/index.jsp"},
	            {id:"015002",text:"Load at once from server",cntext:"从服务器上一次性加载数据",pid:"015",url:"/new_3_7/load_at_once_from_server/index.jsp"},
	            {id:"015003",text:"Single search",cntext:"单一搜索",pid:"015",url:"/new_3_7/single_search/index.jsp"},
	            {id:"015004",text:"Multiple search",cntext:"多重搜索",pid:"015",url:"/new_3_7/multiple_search/index.jsp"},
	            {id:"015005",text:"Virtual scrolling",cntext:"虚拟滚动条",pid:"015",url:"/new_3_7/virtual_scrolling/index.jsp"},
	            {id:"015006",text:"Toolbar search",cntext:"搜索工具栏",pid:"015",url:"/new_3_7/toolbar_search/index.jsp"},
	            {id:"015007",text:"Add/edit/delete on local data",cntext:"本地数据的增删改",pid:"015",url:"/new_3_7/add_edit_delete_on_local_data/index.jsp"},
	            {id:"016",text:"Grouping",cntext:"分组",pid:"root"},
	            {id:"016001",text:"Simple grouping with array data",cntext:"数组数据的简单分组",pid:"016",url:"/grouping/simple_grouping_with_array_data/index.jsp"},
	            {id:"016002",text:"Hide grouping column",cntext:"隐藏分组列",pid:"016",url:"/grouping/hide_grouping_column/index.jsp"},
	            {id:"016003",text:"Grouped header row config",cntext:"分组表头行配置",pid:"016",url:"/grouping/grouped_header_row_config/index.jsp"},
	            {id:"016004",text:"RTL Support",cntext:"RTL支持",pid:"016",url:"/grouping/rtl_support/index.jsp"},
	            {id:"016005",text:"grouping row(s) collapsed",cntext:"分组行折叠",pid:"016",url:"/grouping/grouping_row_s__collapsed/index.jsp"},
	            {id:"016006",text:"Summary Footers",cntext:"汇总页脚",pid:"016",url:"/grouping/summary_footers/index.jsp"},
	            {id:"016007",text:"Remote Data(sorted)",cntext:"远程数据(排序过)",pid:"016",url:"/grouping/remote_data__sorted/index.jsp"},
	            {id:"016008",text:"Remote Data(sorted with grandtotals)",cntext:"远程数据(grandtotals排序)",pid:"016",url:"/grouping/remote-data__sorted_with_grandtotals/index.jsp"},
	            {id:"016009",text:"Dynamically change grouping",cntext:"动态改变分组",pid:"016",url:"/grouping/dynamically_change_grouping/index.jsp"},
	            {id:"016010",text:"View Summary Row on Collapse",cntext:"折叠的汇总行",pid:"016",url:"/grouping/view_summary_row_on_collapse/index.jsp"},
	            {id:"016011",text:"Multi Group all level sums(new)",cntext:"多分组所有级数求和(新)",pid:"016",url:"/grouping/multi_group_all_level_sums__new/index.jsp"},
	            {id:"016012",text:"Multi Group one level sum(new)",cntext:"多表头单级数求和(新)",pid:"016",url:"/grouping/multi_group_one_level_sum__new/index.jsp"},
	            {id:"016013",text:"Multi Group Show sums on header(new)",cntext:"多分组在头部显示求和(新)",pid:"016",url:"/grouping/multi_group_show_sums_on_header_new/index.jsp"},
	            {id:"017",text:"Functionality",cntext:"功能",pid:"root"},
	            {id:"017001",text:"Data colspan",cntext:"数据合并单元格",pid:"017",url:"/functionality/data_colspan/index.jsp"},
	            {id:"017002",text:"Keyboard navigation",cntext:"键盘导航",pid:"017",url:"/functionality/keyboard_navigation/index.jsp"},
	            {id:"017003",text:"Column model templates",cntext:"列模型模板",pid:"017",url:"/functionality/column_model_templates/index.jsp"},
	            {id:"017004",text:"Add tree mode",cntext:"树模式添加数据",pid:"017",url:"/functionality/add_tree_node/index.jsp"},
	            {id:"017005",text:"Form atter actions",cntext:"表单预定义函数",pid:"017",url:"/functionality/formatter_actions/index.jsp"},
	            {id:"017006",text:"Multi sorting",cntext:"多级排序",pid:"017",url:"/functionality/multi_sorting/index.jsp"},
	            {id:"018",text:"Searching",cntext:"搜索",pid:"root"},
	            {id:"018001",text:"Complex search",cntext:"复杂搜索",pid:"018",url:"/searching/complex_search/index.jsp"},
	            {id:"018002",text:"Show query in search",cntext:"在搜索中显示查询条件",pid:"018",url:"/searching/show_query_in_search/index.jsp"},
	            {id:"018003",text:"Validation in search",cntext:"搜索中验证数据",pid:"018",url:"/searching/validation_in_serach/index.jsp"},
	            {id:"018004",text:"Search Templates",cntext:"搜索模板",pid:"018",url:"/searching/search_templates/index.jsp"},
	            {id:"018005",text:"Toolbar with Operations",cntext:"搜索操作工具栏",pid:"018",url:"/searching/toolbar_with_operations/index.jsp"},
	            {id:"019",text:"Hierarchy",cntext:"层级",pid:"root"},
	            {id:"019001",text:"Custom Icons",cntext:"自定义图标",pid:"019",url:"/hierarchy/custom_icons/index.jsp"},
	            {id:"019002",text:"Expand all Rows on load",cntext:"加载时展开所有行",pid:"019",url:"/hierarchy/expand_all_rows_on_load/index.jsp"},
	            {id:"019003",text:"Load subgrid data only once",cntext:"一次性加载多级表格数据",pid:"019",url:"/hierarchy/load_subgrid_data_only_once/index.jsp"},
	            {id:"020",text:"Frozen Cols. Group Header",cntext:"冻结列分组头",pid:"root"},
	            {id:"020001",text:"Group Header - no colspan style",cntext:"分组表头-没有合并列的样式",pid:"020",url:"/frozen_cols_group_header_new/group_header__no_colspan_style/index.jsp"},
	            {id:"020002",text:"Group Header - with colspan style",cntext:"分组表头-有合并列的样式",pid:"020",url:"/frozen_cols_group_header_new/group_header__with_colspan_style/index.jsp"},
	            {id:"020003",text:"Frozen column",cntext:"冻结列",pid:"020",url:"/frozen_cols_group_header_new/frozen_column/index.jsp"},
	            {id:"020004",text:"Frozen column with group header",cntext:"冻结带有分组头的列",pid:"020",url:"/frozen_cols_group_header_new/frozen_column_with_group_header/index.jsp"},
	            {id:"021",text:"Pivot Grid",cntext:"Pivot Grid",pid:"root"},
	            {id:"021001",text:"Basic Pivot",cntext:"Basic Pivot",pid:"021",url:"/pivot_grid/basic_pivot/index.jsp"},
	            {id:"021002",text:"Grouping rows",cntext:"分组行",pid:"021",url:"/pivot_grid/grouping_rows/index.jsp"},
	            {id:"021003",text:"Grouping with summary at footer",cntext:"带有汇总页脚的分组",pid:"021",url:"/pivot_grid/grouping_with_summary_at_footer/index.jsp"},
	            {id:"021004",text:"Column groups",cntext:"列分组",pid:"021",url:"/pivot_grid/column_groups/index.jsp"},
	            {id:"021005",text:"Totals by columns and rows",cntext:"行列总计",pid:"021",url:"/pivot_grid/totals_by_columns_and_rows/index.jsp"},
	            {id:"021006",text:"Frozen groups columns",cntext:"冻结分组列",pid:"021",url:"/pivot_grid/frozen_grops_columns/index.jsp"},
	            {id:"021007",text:"Many Summary values",cntext:"多个汇总值",pid:"021",url:"/pivot_grid/many_summary_values/index.jsp"},
	            {id:"021008",text:"Searching",cntext:"搜索",pid:"021",url:"/pivot_grid/searching/index.jsp"}
	            ];
	$("#listMenu").listMenu("load",data);
}
var tabUrlList = new Object();
var tabLength = 0;
function addTab(title,url){
	if(tabLength>5){
		alert("请先尝试关闭一些页面，再打开新页面");
		return;
	}
	if(tabUrlList[url]){
		selectTab(url);
		return;
	}
	tabUrlList[url] = "1";
	tabLength++;
	var titleDom = $('<div class="title-item" style=" ">窗口1</div>');
	var contentDom = $('<iframe src="" frameborder="0"></iframe>');
	
	titleDom.attr({
		src:url,
		title:title
	}).html(title);
	contentDom.attr({
		src:url
	});
	$(".right-pane-title").append(titleDom);
	$(".right-pane-content").append(contentDom);
	selectTab(url);
	
}
function selectTab(url){
	$(".right-pane-title .selected").removeClass("selected");
	$(".right-pane-title").find("[src='"+url+"']").addClass("selected");
	$(".right-pane-content iframe").hide();
	$(".right-pane-content").find("[src='"+url+"']").show();
}
function closeTab(){
	var selected = $(".right-pane-title .selected");
	if(selected.attr("freeze") === "true"){
		return;
	}
	var next = selected.next();
	var prev = selected.prev();
	if(next.length>0){
		tabUrlList[selected.attr("src")] = null;
		tabLength--;
		next.addClass("selected");
		$(".right-pane-content").find("[src='"+selected.attr("src")+"']").remove();
		selected.remove();
		selectTab(next.attr("src"));
	}else if(prev.length>0){
		tabUrlList[selected.attr("src")] = null;
		tabLength--;
		$(".right-pane-content").find("[src='"+selected.attr("src")+"']").remove();
		selected.remove();
		selectTab(prev.attr("src"));
	}
}











